<?php
namespace Orm\PlayShowings;

use Base\Exception\RmException;
class PlayShowingsClass extends \Base\BaseOrmObject{
    protected   $id,
				$type = 0, // 小组类别
				$player_a = 0, // 比赛球队-A
				$player_b = 0, // 比赛球队-B
				$start_date = '', // 比赛日期
				$start_time = '', // 比赛时间
				$play_number = 0, // 比赛场次
				$open_time = '', // 开放时间
				$stop_time = '', // 竞猜截止时间
				$score_a = 0, // 比分A
				$score_b = 0, // 比分B
				$status = 0, // 1,已结束
                $exec_week_score = 0, //是否执行周排行
                $week_own = 1, //所属周
				$is_del = 0,
				$insert_time = '',
				$update_time = '';

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\PlayShowings\PlayShowingsModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'type' => $this->type,
			'player_a' => $this->player_a,
			'player_b' => $this->player_b,
			'start_date' => $this->start_date,
			'start_time' => $this->start_time,
			'play_number' => $this->play_number,
			'open_time' => $this->open_time,
			'stop_time' => $this->stop_time,
			'score_a' => $this->score_a,
			'score_b' => $this->score_b,
			'status' => $this->status,
            'exec_week_score' => $this->exec_week_score,
            'week_own' => $this->week_own
        );

        $model = new \Orm\PlayShowings\PlayShowingsModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'type' => $this->type,
			'player_a' => $this->player_a,
			'player_b' => $this->player_b,
			'start_date' => $this->start_date,
			'start_time' => $this->start_time,
			'play_number' => $this->play_number,
			'open_time' => $this->open_time,
			'stop_time' => $this->stop_time,
			'score_a' => $this->score_a,
			'score_b' => $this->score_b,
			'status' => $this->status,
            'exec_week_score' => $this->exec_week_score,
            'week_own' => $this->week_own
        );

        $model = new \Orm\PlayShowings\PlayShowingsModel();
        $is_update = $model->update($data, "`id` = {$this->id}");
        return $is_update;
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\PlayShowings\PlayShowingsModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }
}